<?php
	
	$iniVars = parse_ini_file('../config.ini',TRUE);
	include('../function/function.php');
	include('../classes/adodb5/adodb.inc.php');
	include('../function/db.func.php');
	
	$name = ($_POST['contact_name']);
	$company = ($_POST['contact_company']);
	$position = ($_POST['contact_position']);
	$email = $_POST['contact_email']; 
	$contact_tel = $_POST['contact_tel']; 
	$contact_time = $_POST['contact_time']; 
	$comments = ($_POST['contact_msg']); 

	$html_mail =  '<strong>ชื่อ : </strong>'.$name;
	$html_mail =  '<strong>หน่วยงาน : </strong>'.$company;
	$html_mail =  '<strong>ตำแหน่ง : </strong>'.$position;
	$html_mail .=  '<br /><strong>อีเมล์ : </strong>'.$email;
	$html_mail .=  '<br /><strong>เบอร์โทร : </strong>'.$contact_tel;
	$html_mail .=  '<br /><strong>เวลาติดต่อ : </strong>'.$contact_time;
	$html_mail .=  '<br /><strong>ข้อความ : </strong><br />'.$comments;
	
	$to      = $iniVars['Etc_Data']['contact_email'];
	
	$subject = 'Message from contact form';
	$message = $html_mail;

	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
	$headers .= "From: $email" . "\r\n" .
		"Reply-To: $email" . "\r\n" .
		'X-Mailer: PHP/' . phpversion();

	$result = @mail($to, $subject, $message, $headers);
	
	if($result)
	{
		include('../function/db.tl.func.php');
		
		$sql = <<<sql
            INSERT INTO contractus VALUES(
		'',
		'{$name}',
		'{$email}',
		'{$contact_time}',
		'{$comments}',
		'{$contact_tel}',
		NOW(),
		'D',
		'1',
		'',
		''
	    )
sql;
		$result = $db->Execute($sql);
		echo 'เราได้รับข้อความของท่านแล้ว';
	}
	else
	{
		echo 'ไม่สามารถส่งข้อความได้ กรุณาลองใหม่อีกครั้ง';
	}
?>